package com.atguigu.demo.customer.controller;


import com.atguigu.demo.customer.bean.Customer;
import com.atguigu.demo.customer.service.CustomerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CustomerController {


    @Autowired
    CustomerService customerService;

  //用主键查询唯一对象
    @RequestMapping(value = "/customer/{id}"  ,method = RequestMethod.GET  )
    public Customer getCustomerById(@PathVariable("id") String id){
        Customer customer = customerService.getCustomerById(id);
        return    customer;

    }
  //条件查询
    @RequestMapping(value = "/customerbyname"  ,method = RequestMethod.GET  )
    public List<Customer> getCustomerByName(@RequestParam("name") String name){
        List<Customer> customerList = customerService.list(new QueryWrapper<Customer>().eq("name", name));

        return   customerList;

    }
    //传递表单
    @PostMapping("/customer")
    public String saveCustomer( @RequestBody Customer customer){
        //customerService.saveCustomer(customer);

        customerService.saveOrUpdate(customer);

        return "success";

    }


}
